# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=ocaml-ounit
_pkgname=ounit
pkgver=2.2.7
pkgrel=3
pkgdesc="A unit test framework for OCaml"
url="https://github.com/gildor478/ounit"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-lwt-dev
	ocaml-seq-dev
	ocaml-stdlib-shims
	"
makedepends="$depends_dev dune ocaml ocaml-findlib"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/gildor478/ounit/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build -p ounit,ounit2 --verbose
}

check() {
	dune runtest -p ounit,ounit2 --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit \
		ounit ounit2
	rm -Rf "$pkgdir"/.omit

	# Install oUnit transition package
	export OCAMLFIND_DESTDIR="$pkgdir/$_ocamldir"
	export OCAMLFIND_LDCONF=ignore
	mkdir -vp "$OCAMLFIND_DESTDIR"
	make install-ounit version=$pkgver
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
b2cefed53127f724c099391eefe1bce3b43cad5d6b629b5f1e9446b58892639de758f5dbcbd5efb6c409ce77ed01d06693989a3ba909cf79c36c2554c1473396  ocaml-ounit-2.2.7.tar.gz
"
